//
// Created by 30938 on 2022/8/30.
//

#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <functional>
#include <ctime>
#include <iomanip>
using namespace std;

void test01() {
    list<int> arr;
    arr.push_back(12);
    arr.push_back(23);
    arr.push_front(34);
    arr.push_front(35);

    for (int val: arr) {
        cout << val << " ";
    }
    cout << endl;

    for (auto it = arr.begin(); it != arr.end(); ++it) {
        cout << *it << " ";
    }
    cout << endl;
}



void test02() {
    list<int> _list{23, 34, 45, 34};
    list<int> _list2(2, 23);
    int arr[] = {23, 34, 23, 12};
    list<int> _list3(arr, arr + sizeof(arr) / sizeof(int));
    for_each(_list3.begin(), _list3.end(),
             [](int val) { cout << val << " "; });
    cout << endl;
}

void test03() {
    vector<vector<int>> arr(5, vector<int>(5, 1));
    for (int i = 0; i < arr.size(); ++i) {
        for (int j = 0; j < arr[i].size(); ++j) {
            cout << arr[i][j] << " ";
        }
        cout << endl;
    }
}
 // 迭代器失效
 // list的删除    容器扩容的时候
 // 删除时导致当前的迭代器失效，无法进行比较操作，程序直接挂掉
void test04(){
    list<int> _list{23,34,23,23,23,45,24,26};
    for(auto it=_list.begin();it!=_list.end();){
        if(*it==23){
            it=_list.erase(it);
        }else{
            ++it;
        }
    }
    for(auto elem:_list){
        cout<<elem<<" ";
    }
    cout<<endl;
}

void test05(){
    list<int> _list={1,2,3,4,5,6,7,8,9};
    _list.reverse();
    for(auto elem:_list){
        cout<<elem<<" ";
    }
    cout<<endl;

    reverse(_list.begin(),_list.end());
    for(auto elem:_list){
        cout<<elem<<" ";
    }
    cout<<endl;

    list<int> _list2(_list.rbegin(),_list.rend());
    for(auto elem:_list2){
        cout<<elem<<" ";
    }
    cout<<endl;

}

void test07(){
    list<int> _list={1,2,3,4,5,6,7,8,9};
    _list.sort();
    for(int &it:_list){
        cout<<it<<" ";
    }
    cout<<endl;

    _list.sort(greater<int>());
    for(int &it:_list){
        cout<<it<<" ";
    }
    cout<<endl;



}

// unique

void test08(){
    list<int> _list{23,34,23,23,23,45,24,26};
    _list.sort();
    _list.unique();
    for(int &it:_list){
        cout<<it<<" ";
    }
    cout<<endl;
}

void test09() {
    list<int> _list{23, 34, 23, 23, 23, 45, 24, 26};
    _list.remove(23);
    for(int &it:_list){
        cout<<it<<" ";
    }
    cout<<endl;

    list<int> _list2(_list);

    _list2.remove_if([](int val){return val % 2 !=0;});
    for(int &it:_list2){
        cout<<it<<" ";
    }
    cout<<endl;
}

void test10(){
    cout<<plus<int>()(15,12)<<endl;
    cout<<minus<int>()(15,12)<<endl;
    cout<<multiplies<int>()(15,12)<<endl;
    cout<<divides<int>()(15,12)<<endl;
    cout<<modulus<int>()(15,12)<<endl;
    cout<<negate<int>()(12)<<endl;
}

void test11()
{
    vector<int > arr={23, 34, 23, 23, 23, 45, 24, 26};
    int cnt=count(arr.begin(),arr.end(),23);
    cout<<cnt<<endl;

    auto it= max_element(arr.begin(),arr.end());
    cout<<*it<<endl;
}

// 排序 sort //搜索 find //替换 replace //max——element min 最值
// 比较 equal // 打印 for——each //反转 reverse // 删除 remove

void test12(){
    char buffer[32];
    time_t tm=time(nullptr); // 时间戳
    struct tm* _tm=localtime(&tm);

    strftime(buffer,sizeof(buffer),"%Y-%m-%d %H:%M:%S",_tm);
    cout<<buffer<<endl;

    cout<< put_time(_tm,"%Y-%m-%d %H:%M:%S")<<endl;
}

int main() {
    test12();
    // test11();
    // test10();
    // test09();
    // test08();
    // test07();
    // test05();
    // test04();
    // test02();
    // test03();
    // test01();
    return 0;
}